package com.lanyou.cook.entity.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.lanyou.cook.common.DefaultDateJsonSerializer;
import com.lanyou.cook.datadictionary.UserLogOpt;
import com.lanyou.cook.service.DataDictionaryService;


@Entity
@EntityListeners({ AuditingEntityListener.class })
@Table(name = "T_COOK_BU_USER_LOG")
public class UserLog{
	//系统用户日志id
	private String id;
	//账号
	private String userCode;
	//登录IP
	private String loginIp;
	//操作时间
	private Date optTime;
	//操作类型
	private String optType;
	//操作人
	private String optPerson;
	//详细信息
	private String contents;
	
	private String creator;

	private String modifier;

	private Date createTime;

	private Date modifyTime;
	
	@Id
	@GeneratedValue(generator = "uuidGenerator")
	@GenericGenerator(name = "uuidGenerator", strategy = "uuid")
	@Column(name = "USER_LOG_ID", length = 36)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	@Column(name="USER_CODE",length=20)
	public String getUserCode() {
		return userCode;
	}

	public void setUserCode(String userCode) {
		this.userCode = userCode;
	}
	@Column(name="LOGIN_IP",length=50)
	public String getLoginIp() {
		return loginIp;
	}

	public void setLoginIp(String loginIp) {
		this.loginIp = loginIp;
	}
	@Column(name="OPT_TIME")
	@JsonSerialize(using = DefaultDateJsonSerializer.class)
	public Date getOptTime() {
		return optTime;
	}

	public void setOptTime(Date optTime) {
		this.optTime = optTime;
	}
	@Column(name="OPT_TYPE",length=DataDictionaryValue.MAX_LENGTH_OF_CODE)
	public String getOptType() {
		return optType;
	}

	public void setOptType(String optType) {
		this.optType = optType;
	}
	@Column(name="OPT_PERSON",length=50)
	public String getOptPerson() {
		return optPerson;
	}

	public void setOptPerson(String optPerson) {
		this.optPerson = optPerson;
	}
	@Column(name="CONTENTS",length=1000)
	public String getContents() {
		return contents;
	}

	public void setContents(String contents) {
		this.contents = contents;
	}

	@CreatedBy
	@Column(length = 50, updatable=false)
	public String getCreator() {
		return creator;
	}

	public void setCreator(String creator) {
		this.creator = creator;
	}

	@LastModifiedBy
	@Column(length = 50)
	public String getModifier() {
		return modifier;
	}

	public void setModifier(String modifier) {
		this.modifier = modifier;
	}

	@Column(name = "CREATED_DATE", updatable=false)
	@JsonSerialize(using = DefaultDateJsonSerializer.class)
	@CreatedDate
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name = "LAST_UPDATED_DATE")
	@JsonSerialize(using = DefaultDateJsonSerializer.class)
	@LastModifiedDate
	public Date getModifyTime() {
		return modifyTime;
	}
	
	public void setModifyTime(Date modifyTime) {
		this.modifyTime = modifyTime;
	}
	
	@Transient
	public String getOptTypeForDisplay() {
		return DataDictionaryService.getInstance().getValueName(UserLogOpt.TypeCode, optType);
	}
	@Transient
	public String getOptTimeForExport(){
		return getOptTime().toString();
	}
}